package struts.listener;

import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.log4j.Logger;

import struts.xml.XMLBean;
import struts.xml.XMLFactory;

public class ActionListener implements ServletContextListener {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger.getLogger(ActionListener.class);

	public static final String STRUTS = "STRUTS";

	public void contextDestroyed(ServletContextEvent sce) {
		// TODO Auto-generated method stub

	}

	public void contextInitialized(ServletContextEvent sce) {
		ServletContext servletContext = sce.getServletContext();
		logger.info("********初始化ActionMapping******");
		String xmlPath = servletContext.getInitParameter("struts-config");
		String root = servletContext.getRealPath("\\");
		Map<String, XMLBean> map = XMLFactory.createXml(root + xmlPath);
		servletContext.setAttribute(ActionListener.STRUTS, map);
	}

}
